<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
	
	
	<p:confirmDialog message="#{msgs.DoYouReallyWantToDeleteThisEntry}"	header="#{msgs.Warning}" severity="alert" widgetVar="wconfExcMod">
		<h:form prependId="false">
			<p:commandButton value="#{msgs.Yes}" oncomplete="wconfExcMod.hide();"	process="@form" actionListener="#{athleteBean.deleteSchedule}"
				update=":tabUser:formAthleteData:modalityTable, :tabUser:formAthleteAvailability:tblAvailability"  />
			<p:commandButton value="#{msgs.No}" onclick="wconfExcMod.hide();"	type="button" />
		</h:form>
	</p:confirmDialog>
	
	<p:dialog id="findAthlete" header="#{msgs.FindAthlete}"   widgetVar="wfindAthlete" modal="true" style="padding: 0px; margin: 0px;"> 
		<h:form id="findAthleteForm" prependId="false">
			<h:panelGrid columns="2" cellpadding="2">

				<h:outputLabel 	value="#{msgs.Name} :" 	for="findByFirstName" />
				<p:inputText	id="findByFirstName" 		value="#{ athleteBean.findByFirstName}" 			maxlength="20" 	size="20" />


				<h:outputLabel 	value="#{msgs.Surname} :" 	for="findBySurname" />
				<p:inputText	id="findBySurname" 		value="#{ athleteBean.findByLastName}" 				maxlength="50" 	size="20" />

	            <h:outputLabel value="#{msgs.CPF} :" for="findByCpf" />
	            <p:inputText id="findByCpf" 	value="#{athleteBean.findByCpf}"							maxlength ="22" size="22" styleClass="cpf" />


				<h:outputLabel	value="#{msgs.Email} :" 			for="findByEmail" />
				<p:inputText id="findByEmail" 				value="#{athleteBean.findByEmail}"				maxlength="50" size="51" />

				<h:outputLabel	value="#{ msgs.CreatedAt} :" />
				<h:column>
					<p:calendar		id="begCreatedAt"	value="#{athleteBean.begCreatedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true" readOnlyInputText="true"  />
	                      #{ msgs.To}
	                <p:calendar		id="endCreatedAt"	value="#{athleteBean.endCreatedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true"	readOnlyInputText="true" />
				</h:column>


				<h:outputLabel	value="#{ msgs.ChangedAt} :" />
				<h:column>
					<p:calendar		id="begChangedAt"	value="#{athleteBean.begChangedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true" readOnlyInputText="true"  />
                      #{ msgs.To}
                    <p:calendar		id="endChangedAt"	value="#{athleteBean.endChangedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true"	readOnlyInputText="true" />
				</h:column>

				<h:outputLabel	value="#{ msgs.ExpireOn} :" />
				<h:column>
				<p:calendar			id="begExpireOn"	value="#{athleteBean.begExpireOn}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true" readOnlyInputText="true"  />
                      #{ msgs.To}
                      <p:calendar	id="endExpireOn"	value="#{athleteBean.endExpireOn}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true"	readOnlyInputText="true" />
				</h:column> 

				<h:outputLabel value="#{ msgs.Status}  :" />
				<p:selectOneRadio value="#{ athleteBean.findByStatus}">
					<f:selectItem itemLabel="#{ msgs.Active}" 		itemValue="true" />
					<f:selectItem itemLabel="#{ msgs.Inactive}" 	itemValue="false" />
				</p:selectOneRadio>
			</h:panelGrid>

			<p:panel id="userModalitys" header="#{msgs.Modalitys}"  toggleable="true" collapsed="true"   >
				<h:panelGrid columns="2"> 
					<h:outputLabel value="#{msgs.ModalityTypes}" for="athleteModalityTypes"/>
				    <p:selectCheckboxMenu id="athleteModalityTypes" value="#{athleteBean.findUserByTrainingTypes}" 
				    	label="#{msgs.ModalityTypes}"  filter="true" panelStyle="width:220px" converter="#{ttConverter}">
		            	<f:selectItems value="#{athleteBean.trainingTypes}"  var="trainingType" itemLabel="#{msgs[trainingType.name]}" itemValue="#{trainingType}" />
						<p:ajax event="change" listener="#{athleteBean.onFindUserByTrainingTypesChange}" update="athleteModalitys"/>
				    </p:selectCheckboxMenu>


					<h:outputLabel value="#{msgs.Modalitys}"/>							
				    <p:selectCheckboxMenu id="athleteModalitys" value="#{athleteBean.findUserByModalitys}" 
				    	label="#{msgs.Modalitys}"  filter="true" panelStyle="width:220px" converter="#{modalityConverter}" >
		            	<f:selectItems value="#{athleteBean.findUserByModalitysAll}"   var="modality" itemLabel="#{modality.name}" itemValue="#{modality}" />
				    </p:selectCheckboxMenu>
				
				</h:panelGrid>	
			</p:panel>
			<p:commandButton value="#{ msgs.Search}"	actionListener="#{athleteBean.search}"	icon=" ui-icon-search"  process="@form" update=":listAthleteForm:athletesTable,:growl" oncomplete="wfindAthlete.hide()" />
			<p:commandButton value="#{ msgs.Clear}"		type="button"	icon="ui-icon-clean">
				 <p:ajax update="findAthleteForm" resetValues="true" />  	
			</p:commandButton>
						
		</h:form>
	</p:dialog>

	<p:dialog id="dlgupload" header="#{msgs.Upload}" widgetVar="wdlgupload" modal="true" style="padding: 0px; margin: 0px;">
		<h:form  prependId="false" enctype="multipart/form-data">
			<p:panel style="width: 600px;height:100px">
				<p:fileUpload fileUploadListener="#{athleteBean.upload}" 
				mode="advanced" 
				styleClass="mobupload"
	            allowTypes="/(\.|\/)(jpg|jpeg)$/"
				sizeLimit="1073741824" 
				cancelLabel="#{msgs.Cancel}"
				label="#{msgs.SelectThePhoto}"
				uploadLabel="#{msgs.Upload}"
				oncomplete="wdlgupload.hide()"
				auto="true"
				invalidFileMessage="#{msgs.InvalidPhotoFormat}"
				update=":messages,:tabUser:formAthleteData:photoAthlete" />
				<br/>
			</p:panel>
		</h:form>
	</p:dialog>
	
	<p:dialog id="findModality" header="#{msgs.FindModality}"  widgetVar="wfindModality" modal="true" >
		<h:form id="formAdddModality" prependId="false">
			<h:panelGrid columns="2" cellpadding="2">

				<h:outputLabel 	value="#{msgs.ModalityName} :" />
				<p:inputText	value="#{ athleteBean.findByModalityName}" 	maxlength="20" 	size="20" />

				<h:outputLabel 	value="#{msgs.ModalityType} :" />

	            <p:selectOneMenu id="modalityType" value="#{athleteBean.findByTrainingType}" converter="#{ttConverter}" >
	            	<f:selectItems value="#{athleteBean.trainingTypes}" var="trainingType" itemLabel="#{msgs[trainingType.name]}" itemValue="#{trainingType}" />
	            </p:selectOneMenu>

				<h:outputLabel 	value="#{msgs.Description} :" />
				<p:inputText	value="#{athleteBean.findByModalityDescription}" 	maxlength="50" 	size="40" />

				<h:outputLabel	value="#{ msgs.CreatedAt} :" />
				<h:column>
					<p:calendar		value="#{athleteBean.begCreatedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true" readOnlyInputText="true"  />
                      #{ msgs.To}
                      <p:calendar	value="#{athleteBean.endCreatedAt}"			locale="pt"		timeZone="Brazil/East" selectOtherMonths="true"	readOnlyInputText="true" />
				</h:column>

				<h:outputLabel	value="#{ msgs.ChangedAt} :" />
				<h:column>
					<p:calendar		value="#{athleteBean.begChangedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true" readOnlyInputText="true"  />
                      #{ msgs.To}
                   	<p:calendar		value="#{athleteBean.endChangedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true"	readOnlyInputText="true" />
				</h:column>
			</h:panelGrid>
			<p:commandButton value="#{ msgs.Search}"	actionListener="#{athleteBean.searchModality}"	icon=" ui-icon-search"  process="@form" update="panelTblSearcModalitys ,:growl" />
			<p:commandButton value="#{ msgs.Clear}"		type="button"	icon="ui-icon-clean">
				 <p:ajax update="formAdddModality" resetValues="true" />  	
			</p:commandButton>

			<p:outputPanel id="panelTblSearcModalitys" layout="block" >
				<p:spacer height="10"/>
				<p:dataTable id="tblSearcModalitys" value="#{athleteBean.modalitys}" var="modality" rendered="#{not empty athleteBean.modalitys}" paginator="true" paginatorAlwaysVisible="false"  paginatorPosition="bottom" rows="8" emptyMessage="#{msgs.NoResults}" >
					<p:column colspan="1"  styleClass="ui-table-button-row">
						<p:commandButton title="#{msgs.Add}" action="#{athleteBean.addModality}" update=":tabUser:formAthleteData:modalityTable, :tabUser:formAthleteAvailability:tblAvailability,  :formAdddModality:panelTblSearcModalitys " icon="ui-icon-plus"  styleClass="ui-table-button">
							<f:setPropertyActionListener target="#{athleteBean.modality}" value="#{modality}"/> 
						</p:commandButton>
					</p:column>
					<p:column headerText="#{msgs.Name}" >
						<h:outputText value="#{modality.name}" />
					</p:column>
					<p:column headerText="#{msgs.ModalityType}" >
						<h:outputText value="#{msgs[modality.trainingType.name]}" />
					</p:column>
					<p:column headerText="#{msgs.Description}" >
						<h:outputText value="#{modality.description}" />
					</p:column>
				</p:dataTable>	
			</p:outputPanel>

		</h:form>
	</p:dialog>

	<p:dialog id="dlgAvailability" header="#{msgs.Availability}"  widgetVar="wdlgAvailability" modal="true" width="650" style="padding: 0px; margin: 0px;" closable="false">
		<h:form id="formAvailability" prependId="false">
		<script type="text/javascript">
		    function handleDialogSubmit(xhr, status, args) {
		        if (args.validationFailed) {
		        	wdlgAvailability.show();
		        } else {
		        	wdlgAvailability.hide();
		        }
		    }
		</script>
			<p:dataTable id="tblScheduleAvailability"  value="#{athleteBean.selScheduleDay}" var="interval" paginator="true" paginatorAlwaysVisible="false"  paginatorPosition="bottom" rows="4" emptyMessage="#{msgs.NoResults}"    >
				<p:columnGroup type="header" >  
					<p:row>
						<p:column colspan="6" style="text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{msgs.AvailableSchedule}"/>
							</f:facet>
						</p:column>
					</p:row>
					<p:row>
						<p:column colspan="1"  styleClass="ui-table-button-row">
							<f:facet name="header">
								<p:commandButton title="#{msgs.Add}" action="#{athleteBean.addTimeInterval}" update=":formAvailability, :tabUser:formAthleteAvailability:tblAvailability" 
									icon="ui-icon-plus" styleClass="ui-table-button"/>
							</f:facet>
						</p:column>
						<p:column	colspan="2">
							<f:facet name="header">
								<h:outputText value="#{msgs.Type}"/> 
							</f:facet>
						</p:column>
						<p:column	colspan="1">
							<f:facet name="header">
								<h:outputText value="#{msgs.BeginHour}"/>
							</f:facet>
						</p:column>
						<p:column	colspan="1" >
							<f:facet name="header">
								<h:outputText value="#{msgs.FinalHour}"/> 
							</f:facet>
						</p:column>
						<p:column	colspan="1" >
							<f:facet name="header">
								<h:outputText value="#{msgs.Interval}"/>
							</f:facet>
						</p:column>
					</p:row>	
				</p:columnGroup>
				<p:column colspan="2" style="white-space:nowrap;">
					<p:commandButton value="#{msgs.Interval}" action="#{athleteBean.changeIntervalType}" 		process="@this" 	style="min-width:150px"
						update="tblScheduleAvailability" rendered="#{interval.type == 1}" >
						<f:setPropertyActionListener target="#{athleteBean.selTimeInterval}" value="#{interval}"  />
						<f:setPropertyActionListener target="#{athleteBean.selTimeInterval.type}" value="#{0}" />
					</p:commandButton>	

					<p:commandButton value="#{msgs.TimeAvailable}" action="#{athleteBean.changeIntervalType}" 	process="@this" 	style="min-width:150px" 
						update="tblScheduleAvailability"  rendered="#{interval.type == 0}" >
						<f:setPropertyActionListener target="#{athleteBean.selTimeInterval}" value="#{interval}" />
						<f:setPropertyActionListener target="#{athleteBean.selTimeInterval.type}" value="#{1}" />
					</p:commandButton>	

				</p:column>		
				<p:column colspan="1" styleClass="ui-table-button-row" > 
					<p:commandButton icon="ui-icon-trash" action="#{athleteBean.deleteTimeInterval}" process="@this"  update="tblScheduleAvailability, :tabUser:formAthleteAvailability:tblAvailability"  styleClass="ui-table-button" >
						<f:setPropertyActionListener target="#{athleteBean.selTimeInterval}" value="#{interval}" />
					</p:commandButton>
				</p:column>

				<p:column  colspan="1" style="white-space: nowrap;"   >
					<p:calendar value="#{interval.begTime}" pattern="HH:mm:ss"    timeOnly="true" locale="pt"  mode="popup"  
						showOn="button" popupIconOnly="true" disabled="#{interval.type != 0}" size="10" required="#{interval.type == 0}" requiredMessage="#{msgs.InputTheTime}" >
						<p:ajax event="dateSelect" update="tblScheduleAvailability" />
					</p:calendar>
				</p:column>	

				<p:column colspan="1"  style="white-space: nowrap;" >
					<p:calendar value="#{interval.endTime}" pattern="HH:mm:ss"    timeOnly="true" locale="pt"  mode="popup"  
						showOn="button" popupIconOnly="true" disabled="#{interval.type != 0}" size="10" required="#{interval.type == 0}" requiredMessage="#{msgs.InputTheTime}">
						<p:ajax event="dateSelect" update="tblScheduleAvailability" />
					</p:calendar>
						
				</p:column>	

				<p:column colspan="1" style="white-space: nowrap;"   >
					<p:calendar value="#{interval.totalTime}" pattern="HH:mm:ss"    timeOnly="true" locale="pt"  mode="popup"  
						showOn="button" popupIconOnly="true" disabled="#{interval.type == 0}" size="10" required="#{interval.type == 1}" requiredMessage="#{msgs.InputTheTime}">
						<p:ajax event="dateSelect" update="tblScheduleAvailability" />
					</p:calendar>
				</p:column>	

				<p:columnGroup type="footer" >  
					<p:row>
						<p:column colspan="6" style="text-align:center;">
							<f:facet name="footer">
								<h:outputText value="#{msgs.TimeAvailable} = #{athleteBean.sumAllIntervals}"/>
							</f:facet>
						</p:column>
					</p:row>
				</p:columnGroup>

			</p:dataTable>

			<p:commandButton actionListener="#{athleteBean.validateIntervals}" value="#{msgs.Close}" 	icon="ui-icon-cancel" update=":growl, :tabUser:formAthleteAvailability:tblAvailability" 	oncomplete="handleDialogSubmit(xhr, status, args)" />				
		</h:form>
	</p:dialog>	

	<p:confirmDialog message="#{msgs.DoYouReallyWantToDeleteThisEntry}"	header="#{msgs.Warning}" severity="alert" widgetVar="wconfExcAthlete">
		<h:form prependId="false">
			<p:commandButton value="#{msgs.Yes}" oncomplete="wconfExcAthlete.hide();"	process="@form" actionListener="#{athleteBean.deleteAthlete}"
				update=":listAthleteForm:athletesTable, :growl, :content"  />
			<p:commandButton value="#{msgs.No}" onclick="wconfExcAthlete.hide();"	type="button" />
		</h:form>
	</p:confirmDialog>	 

</html>
		